package com.example.module_word.room

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.module_word.search.entity.DictionaryResult
import kotlinx.coroutines.flow.Flow

@Dao
interface CourseDao {


    //-------------------搜索记录------------------------

    /**
     * 获取搜索记录
     */
    @Query("SELECT * FROM searchhistory order by updateTime DESC limit 3")
    fun getSearchHistoryList():Flow<List<DictionaryResult>>

    /**
     * 根据word获取搜索记录
     */
    @Query("SELECT * FROM searchhistory where word = :word")
    fun getSearchHistoryListByWord(word:String): DictionaryResult?

    /**
     * 添加搜索记录
     */
    @Insert()
    fun insertSearchHistoryList(dictionaryResult: DictionaryResult)

    /**
     * 修改搜索记录
     */
    @Update()
    fun updateSearchHistoryList(dictionaryResult: DictionaryResult)

    /**
     * 删除搜索记录
     */
    @Query("delete from searchhistory")
    fun deleteSearchHistoryList()
}